<template>
    <div>
        <div class="weui-header bg-green" style="position: fixed;top: 0; width: 100%;z-index: 500;"> 
            <div class="weui-header-left" @click="goBack">
                <svg class="icon white" aria-hidden="true">
                    <use xlink:href="#icon-fanhui"></use>
                </svg>
            </div>
            <h1 class="weui-header-title">选择练习题库</h1>
        </div>
        <div style="height:50px"></div>
        <TreeList
            :dataList='lists'
            value-key='CLASS_CODE'
            label-key='CLASS_INFO'
            v-on:clickItem="onClickItem"
            :hasArrow="true" 
            :hasCheckBox="false"
        />     
    </div>
</template>

<script>
import TreeList from '../../components/TreeList.vue';
export default {
    components: {
      TreeList
    },
    data () {
        return {
            selectVal: {},
            lists: []
        }
    },
    methods: {
        goBack(){
            this.$router.go(-1);
        },
        //点击项目
        onClickItem(item){
            if(item.QUESTION_NUMBER==0){
                this.$weui.alert("该题库内没有任何题目");
            }
            else{
                this.$router.push({name:'TrainingQuestionView',query:{classCode:item.CLASS_CODE,QUESTION_NUMBER:item.QUESTION_NUMBER}});
            }
        },
        //获取数据
        getTreeList () {
            var loading           = this.$weui.loading('数据处理中…');
            this.$api.Training.GetClassTree().then((msg)=>{
                loading.hide();
                if(msg.data.R){
                    this.lists = msg.data.D;
                }
                else{
                    this.$weui.alert(msg.data.I);
                }
            }).catch((response)=> {
                loading.hide();
                // 响应错误回调
                this.$weui.alert("调用http错误，代码:" + response.message);
            });  

        }
    },
    created  () {
        
        document.title="题库分组"  
        this.getTreeList();
    }
}
</script>

<style>

</style>